<?php
/**
 * CreateView.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/25
 * Time: 14:23
 */
namespace app\console\command\auto_curd\tpl;

class CreateView
{
    static public function begin($tableName)
    {
        $date = date('Y/m/d',time());
        $time = date('H:i',time());
        $tpl = <<<EOF

{extend name="common@bootstrap" /}
{block name="body_content"}
<div class="btn-group">
    <a href="{:url('read')}" class="btn btn-default">列表</a>
</div>
<form action="{:url('create')}" method="post" role="form" data-auto-date="$date" data-auto-time="$time">

EOF;
        return $tpl;
    }

    static public function content($column)
    {
        // 字符类型
        if(in_array($column['data_type'],['char','varchar','tinytext']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="text" class="form-control" id="input-{$column['column_name']}" name="{$column['column_name']}" value="{$column['column_default']}" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;

        }
        // 字符类型
        else if(in_array($column['data_type'],['text','mediumtext','longtext']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="textarea-{$column['column_name']}">{$column['column_comment']}</label>
        <textarea class="form-control" id="textarea-{$column['column_name']}" name="{$column['column_name']}" placeholder="请输入{$column['column_comment']}" rows="3">{$column['column_default']}</textarea>
    </div>

EOF;
        }
        // 日期和时间类型
        else if(in_array($column['data_type'],['date']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="date" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        // 日期和时间类型
        else if(in_array($column['data_type'],['time']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="time" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        // 日期和时间类型
        else if(in_array($column['data_type'],['year']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="number" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" maxlength="4" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        // 日期和时间类型
        else if(in_array($column['data_type'],['datetime','timestamp']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="datetime-local" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" maxlength="4" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        // 数值类型
        else if(in_array($column['data_type'],['tinyint','smallint','mediumint','int','bigint','float','double','decimal']))
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="number" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        // 其他类型
        else
        {
            $tpl = <<<EOF

    <div class="form-group">
        <label for="input-{$column['column_name']}">{$column['column_comment']}</label>
        <input type="text" class="form-control" id="input-{$column['column_name']}" value="{$column['column_default']}" placeholder="请输入{$column['column_comment']}">
    </div>

EOF;
        }
        return $tpl;
    }

    static public function end()
    {
        $tpl = <<<EOF

    <button type="submit" class="btn btn-default">确定</button>
</form>
{/block}

EOF;
        return $tpl;
    }
}